<include file="Public/header"/>
<body class="body-bg">
<form id="pay" action="http://tqr.frontpay.cn/sinochem/order/comfirmpay" method="post">
    <input type="hidden" name="token" id="token">
</form>
<div class="park-header">
    <div class="park-header__title">订单支付</div>
    <div class="park-header__left" onclick="window.location='/Home/User/order/';">
        <i class="iconfont icon-fanhui"></i>
    </div>
</div>
<div class="container">
    <div class="park-payOrder-info">
        <p class="park-payOrder-info__title"><i class="park-success-icon"></i>&nbsp;&nbsp;订单已经提交成功！</p>
        <p class="park-payOrder-info__tips">请你在{$info.add_time}前完成支付否则订单将自动取消！</p>
        <p class="park-payOrder-info__num">订单号：{$info.order_sn}</p>
        <p class="park-payOrder-info__price">支付金额：￥{$info.order_price}</p>
    </div>
    <div class="park-payOrder-type">
        <p class="park-payOrder-type__title">支付方式（必选）</p>
        <div class="park-payOrder-type-list">
            <ul>
                <li>
                    <div class="left"><i class="park-wechat-icon"></i>&nbsp;&nbsp;<span>微信支付</span></div>
                    <div class="right">
                        <label class="park-form">
                            <input type="radio" name="pay_type" <if condition="$info.pay_type eq '微信支付'"> checked </if> class="park-form__radio" value="微信支付">
                            <span class="park-form__radioInput"></span>
                        </label>
                    </div>
                </li>
                <li>
                    <div class="left"><i class="park-yue-icon"></i>&nbsp;&nbsp;<span>余额支付</span></div>
                    <div class="right">
                        <label class="park-form">
                            <input type="radio" name="pay_type" <if condition="$info.pay_type eq '余额支付'"> checked </if> class="park-form__radio" value="余额支付">
                            <span class="park-form__radioInput"></span>
                        </label>
                    </div>
                </li>
            </ul>
        </div>
    </div>
    <div class="park-btn park-btn-default park-btn-bottom mt-footer__btn" onclick="sub_imme();">立即支付</div>
</div>
<div id="pay-modal" class="pay-modal">
    <div class="pay-modal-container">
        <div class="pay-modal-header">
            <i class="iconfont icon-del close"></i>
            <span class="title">请输入支付密码</span>
        </div>
        <div class="pay-modal-body">
            <form id="pay-form">
                <div class="pay-modal-body__title">余额支付</div>
                <div class="pay-modal-body__input">
                    <input id="pay-input" type="password" maxlength="6" onkeyup="check_pwd(this);" placeholder="请输入六位数密码" onkeyup="this.value = this.value.replace(/[^\d]/g, '')">
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script src="__ROOT__/Public/Home/layer/layer.js"></script>
<script>
	window.pay_id = true;
    //立即支付
    function sub_imme(){
		var id = '{$info.id}';
		var pay_type = $('input[name="pay_type"]:checked').val();
		if(pay_type=='余额支付'){
			if(pay_id) {
                $('#pay-modal').show();
                return false;
            }
			var pwd = $('#pay-input').val();
			$.post('/Home/User/imme_order_yue/',{'order_id':id,pay_type:pay_type,pwd:pwd},function(data){
				layer.open({
					content:data.msg
					,skin: 'msg'
					,time: 2 //2秒后自动关闭
				});
				if(data.code==200){
					window.location = '/Home/User/order/';
				}
			},'json');
		}else{
			$.post('/Home/User/imme_order/',{'order_id':id,pay_type:pay_type},function(data){
				if(data.code==200){
					$('#token').val(data.result);
					$('#pay').submit();
				}
			},'json');
		}
    }
	//判断支付密码是否正确
    function check_pwd(obj){
        var number = $(obj).val();
        if(number.length==6) {
			$('#pay-input').blur();
            $.post('/Home/Cart/pay_type/',{pwd:number},function(data){
                if(data.code==100){
                    $(obj).val('');
                    layer.open({
                        content:data.msg
                        ,skin: 'msg'
                        ,time: 2 //2秒后自动关闭
                    });
                }else if(data.code==200){
                    window.pay_id = false;
					sub_imme();
                }
            },'json');
            $('#pay-modal').hide();
        }
    }
	$(function(){
		pushHistory(); 
	    window.addEventListener("popstate", function(e) { 
		 	window.location = '/Home/User/order/';
	    }, false); 
	});
	function pushHistory() { 
		var state = { 
			title: "title", 
			url: "#"
		}; 
		window.history.pushState(state, "title", "#"); 
	}	
</script>
</html>